home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d963.lha / SIOD / scm / gcd-machine.scm < prev    next >
Text File  |  1993-05-08  |  2KB  |  38 lines

  1. (define gcd
  2.         (build-model '(a b t)
  3.                      '(test-b
  4.                        (branch (zero? (fetch b)) gcd-done)
  5.                        (assign t (remainder (fetch a) (fetch b)))
  6.                        (assign a (fetch b))
  7.                        (assign b (fetch t))
  8.                        (goto test-b)
  9.                        gcd-done)))
  10.  
  11. (define fact
  12.         (build-model '(n val continue)
  13.                      '((assign continue fib-done)
  14.                      fib-loop
  15.                        (branch (< (fetch n) 2) immediate-answer)
  16.                        (save continue)
  17.                        (assign continue after-fib-n-1)
  18.                        (save n)
  19.                        (assign n (- (fetch n) 1))
  20.                        (goto fib-loop)
  21.                      after-fib-n-1
  22.                        (restore n)
  23.                        (restore continue)
  24.                        (assign n (- (fetch n) 2))
  25.                        (save continue)
  26.                        (assign continue after-fib-n-2)
  27.                        (save val)
  28.                        (goto fib-loop)
  29.                      after-fib-n-2
  30.                        (assign n (fetch val))
  31.                        (restore val)
  32.                        (restore continue)
  33.                        (assign val (+ (fetch val) (fetch n)))
  34.                        (goto (fetch continue))
  35.                      immediate-answer
  36.                        (assign val (fetch n))
  37.                        (goto (fetch continue))
  38.                      fib-done)))